<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * simple class for validating data
 *
 * @author Administrator
 */
class Validator {
    //put your code here
   

    
    private $_errorList;
    
    public function IsEmpty($field, $msg)
    {
$value = $this->_getValue($field);

if (trim($value) == "")
{
//$this->_errorList = array($field=>$msg);
$this->_errorList[$field]=$msg;

return false;
}
else
{
return true;
}
}
    
    public function IsString($field, $msg)
    {
$value = $this->_getValue($field);
if(!is_string($value))
{
$this->_errorList[$field]=$msg;
return false;
}
else
{
return true;
}
}
    
    public function IsNumber($field, $msg)
    {
$value = $this->_getValue($field);
if(!is_numeric($value))
{
$this->_errorList[$field]=$msg;
return false;
}
else
{
return true;
}
}
    
    public function isAlpha($field, $msg)
    {
$value = $this->_getValue($field);
$pattern = "/^[a-zA-Z]+$/";
if(preg_match($pattern, $value))
{
return true;
}
else
{
$this->_errorList[$field]=$msg;
return false;
}
}

    function isEmailAddress($field, $msg)
    {
$value = $this->_getValue($field);
$bol = filter_var($value, FILTER_VALIDATE_EMAIL);
if($bol)
{
return true;
}

else
{
$this->_errorList[$field]=$msg;
return false;
}
}

    public function IsError()
    {
        if (sizeof($this->_errorList) > 0)
    
{
return true;
}
else
{
return false;
}



        
    }
    
    public function getErrorList()
    {
        return $this->_errorList;
    }
    
    public function resetErrorList()
    {
        $this->_errorList = array();
    }
    
    private function _getValue($field)
    {
        return $_POST[$field];
    }
    
    public $pseudopost;

}

?>
